<?php
		use Zend\Session\Container;

		$SESSION = new Container('user');
		include_once 'DidwwApi.php';
		if(!isset($_SESSION['total'])) {
			$uname = "kemamurali@gmail.com"; // API username
			$key   = "C80E2P960T0PP0ZVNNTHDC"; // API key
			$test = false; // if test mode disabled - false
			
			$api = new DidwwApi($uname,$key,$test);
			$iso = 0; $city_prefix = 0; $last_request_gmt = 0;
			$regions = $api->getRegions($iso, $city_prefix, $last_request_gmt);
			$data = array();
			$data = $regions;
			$countries = array();
			//echo '<pre>';
			//print_r($data);exit;
			$Allcountry='';$y='';$total='';
			for($q=0;$q<count($data);$q++)
			{
				$y=$y.str_replace(" ", '', $data[$q]->country_name).'@';
			}
			$Allcountry=trim($y,"@");
			$total=$total.$Allcountry."%";
			$city = array();
			$a='';$b='';$c='';$d='';
			for($i=0;$i<count($data);$i++)
			{
				for($k=0;$k<count($data[$i]->cities);$k++)
				{
					$z=$data[$i]->cities[$k]->city_name;
					$z=str_replace("-", '', $z);
					$a=$a.preg_replace('/( *)/', '',$z);
					$a=$a.'&'.$data[$i]->cities[$k]->monthly;
					$a=$a.'&'.$data[$i]->cities[$k]->city_prefix;
					$a=$a.',';
				}
					$a=trim($a,",");
					$b=$b.'@'.$a;
					$a='';
			}
				$b=ltrim($b,"@");
				//$total=$total.$b."%";
			//echo $b;exit;
			for($i=0;$i<count($data);$i++)
			{
				$flag = 0;
				for($k=0;$k<count($data[$i]->cities);$k++)
				{
					if($data[$i]->cities[$k]->isavailable == 1)
					{
						$flag = 1;
						break;
					}
				}
				if($flag == 1)
				{
					$countries[$i] = array('country_name'=>$data[$i]->country_name,
					'country_prefix'=>$data[$i]->country_prefix,
					'country_iso'=>$data[$i]->country_iso);
					$c=$c.$data[$i]->country_prefix;
					$c=$c."*";
				}
				$d=$d.$c;
				$c='';
			}
				$d=trim($d,"*");
				$total=$total.$d."%".$b;
				$_SESSION['total'] = $total;
				echo $total;exit;
		} else {
				echo $total = $_SESSION['total'];exit;
		}
			//return '$total';
?>